package com.atxyj.springsecurity.system.exception;

import org.apache.commons.lang3.ObjectUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author xieyujiao
 * @description 自定义异常类
 * @date 2021/7/30
 */
abstract class BaseException extends RuntimeException {

    private final ErrorCode errorCode;
    private final transient Map<String, Object> data = new HashMap<>();

    BaseException(ErrorCode errorCode, Map<String, Object> data) {
      super(errorCode.getMessage());
      this.errorCode = errorCode;
      if(!ObjectUtils.isEmpty(data)) {
          this.data.putAll(data);
      }
    }

    BaseException(ErrorCode errorCode, Map<String, Object> data, Throwable cause) {
       super(errorCode.getMessage(), cause);
       this.errorCode = errorCode;
       if(!ObjectUtils.isEmpty(data)) {
          this.data.putAll(data);
       }
    }

    public ErrorCode getErrorCode() { return errorCode; }

    public Map<String, Object> getData() { return data;}

}
